import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['super-admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/showRequest',
    name: '门店申请',
    component: () => import('@/views/storeAdmin/storeAdmin/showRequest'),
    hidden: true
  },
  {
    path: '/showSupplier',
    name: '供应商申请',
    component: () => import('@/views/zjm_supplierFoods/supplierApply/showRequest'),
    hidden: true
  },
  {
    path: '/reg',
    component: () => import('@/views/reg/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        component: () => import('@/views/dashboard/index'),
        name: '首页',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: '设置',
        meta: { title: '设置', icon: 'user', noCache: true }
      }
    ]
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/useradmin',
    component: Layout,
    redirect: '/useradmin',
    children: [
      {
        path: 'user',
        component: () => import('@/views/useradmin'),
        name: '用户管理',
        meta: { title: '用户管理', icon: 'user', roles: ['super-admin'] }
      }
    ]
  },
  {
    path: '/master',
    component: Layout,
    children: [
      {
        path: 'petuser',
        component: () => import('@/views/petuser'),
        name: '宠主管理',
        meta: { title: '宠主管理', icon: 'tab', roles: ['super-admin'] }
      }
    ]
  },
  {
    path: '/count',
    component: Layout,
    redirect: '/goodscount',
    meta: {
      title: '统计',
      icon: 'dashboard',
      roles: ['store'] // you can set roles in root nav
    },
    children: [
      {
        path: 'goodscount',
        component: () => import('@/views/storeAdmin/goodscount'),
        name: 'goodscount',
        meta: {
          title: '门店商品统计',
          roles: ['store'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'servicecount',
        component: () => import('@/views/storeAdmin/servicecount'),
        name: 'servicecount',
        meta: {
          title: '门店服务统计',
          roles: ['store'] // or you can only set roles in sub nav
        }
      },
    ]
  },
  {
    path: '/review',
    component: Layout,
    redirect: '/review/supplier',
    alwaysShow: true, // will always show the root menu
    name: 'supplier',
    meta: {
      title: '审核中心',
      icon: 'list',
      roles: ['super-admin'] // you can set roles in root nav
    },
    children: [
      {
        path: 'supplier',
        component: () => import('@/views/Review/supplier'),
        name: '供应商审核',
        meta: {
          title: '供应商审核',
          roles: ['super-admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'store',
        component: () => import('@/views/Review/store'),
        name: 'store',
        meta: {
          title: '门店审核'
          // if do not set roles, means: this page does not require permission
        }
      },
    ]
  },
  {
    path: '/storemap',
    component: Layout,
    children: [
      {
        path: 'map',
        component: () => import('@/views/storemap'),
        name: '全国门店分布',
        meta: { title: '全国门店分布', icon: 'money', roles: ['super-admin'] }
      }
    ]
  },
  {
    path: '/xh_supplier',
    component: Layout,
    children: [
      {
        path: 'suppliercount',
        component: () => import('@/views/xh_supplier/xh_supplierCharts'),
        name: '供应商管理统计图',
        meta: { title: '供应商管理统计图', icon: 'user', roles: ['super-admin'] }
      },
    ]
  },
  {
    path: '/gya_supplier',
    component: Layout,
    children: [
      {
        path: 'salesStatistics',
        component: () => import('@/views/salesStatistics/salesStatistics'),
        name:'销售额占比统计',
        meta: { title: '销售额占比统计', icon: 'dashboard', affix: true,roles: ['super-admin'] }
      },
    ]
  },
  // 门店路由
  {
    path: '/store',
    component: Layout,
    redirect: '/store/goods',
    alwaysShow: true, // will always show the root menu
    name: 'Store',
    meta: {
      title: '门店管理',
      icon: 'lock',
      roles: ['store'] // you can set roles in root nav
    },
    children: [
      {
        path: 'goods',
        component: () => import('@/views/storeAdmin/goods'),
        name: 'storeGoodsAdmin',
        meta: {
          title: '门店商品管理',
          roles: ['store']
        // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'order',
        component: () => import('@/views/storeAdmin/order'),
        name: '订单管理',
        meta: {
          title: '订单管理',
          roles: ['store']
        // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'server',
        component: () => import('@/views/storeAdmin/server'),
        name: 'storeServerAdmin',
        meta: {
          title: '门店服务管理',
          roles: ['store']
        }
      },
      {
        path: 'supplier',
        component: () => import('@/views/storeAdmin/supplier'),
        name: '供应商管理',
        meta: {
          title: '供应商商品',
          roles: ['store']
        }
      }
    ]
  },
  // 供应商路由
  {
    path: '/supplier',
    component: Layout,
    children: [
      {
        path: 'foods',
        component: () => import('@/views/zjm_supplierFoods/supplierFoods'),
        name: '供应商商品管理',
        meta: { title: '供应商商品管理', icon: 'tab', roles: ['supplier'] }
      }
    ]
  },
  {
    path: '/supplierSC',
    component: Layout,
    children: [
      {
        path: 'tj',
        component: () => import('@/views/zjm_supplierFoodsSC/supplierFoodsSC'),
        name: '供应商销量统计',
        meta: { title: '供应商销量统计', icon: 'list', roles: ['supplier'] }
      }
    ]
  }
  /** when your routing map is too long, you can split it into small modules **/
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
